package com.logic.modular.game.robot.player;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.comment.pojo.domain.logic.domain.Player;
import com.logic.modular.game.player.info.service.PlayerServiceImpl;
import com.logic.modular.gameCore.config.service.impl.CoreConfigServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 人机账户行为
 */
@Slf4j
@Service
public class RobotPlayerActionServiceImpl {
    @Resource
    private PlayerServiceImpl playerServiceImpl;

    /**
     * 机器人初始化-(人机账户)
     */
    public void tryInit() {
        long l = System.currentTimeMillis();
        // 获取初始值
        int robotInitValue = CoreConfigServiceImpl.getCache(6L).getValue1().intValue();
        // 找出新的机器人ID
        for (long newRobotId = 1; newRobotId <= robotInitValue; newRobotId++) {
            long count = playerServiceImpl.count(new LambdaQueryWrapper<Player>().eq(Player::getUid, newRobotId));
            if (count == 0) {
                Player player = Player.createRobotPlayer(newRobotId);
                try {
                    playerServiceImpl.init(player);
                } catch (Exception e) {
                    log.info("机器人:{}初始化失败:", newRobotId, e);
                }
            }
        }
        log.info("机器人初始化完成,耗时:{}ms", System.currentTimeMillis() - l);
    }
}
